package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Daily;
import cn.wolfcode.trip.base.domain.Enshrine;
import cn.wolfcode.trip.base.mapper.DailyMapper;
import cn.wolfcode.trip.base.mapper.EnshrineMapper;
import cn.wolfcode.trip.base.service.IEnshrineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class EnshrineServiceImpl implements IEnshrineService {

    @Autowired
    private EnshrineMapper enshrineMapper;
    @Autowired
    private DailyMapper dailyMapper;


    public int deleteByPrimaryKey(Long userId, Long dailyId) {
     return enshrineMapper.deleteByPrimaryKey(userId,dailyId);
    }

    public int insert(Enshrine record) {
        return enshrineMapper.insert(record);
    }

    public Enshrine selectByPrimaryKey(Long id) {
        return enshrineMapper.selectByPrimaryKey(id);
    }

    public List<Enshrine> selectAll() {
        return enshrineMapper.selectAll();
    }

    public int updateByPrimaryKey(Enshrine record) {
        return enshrineMapper.updateByPrimaryKey(record);
    }

    public int selectForHave(Long userId, Long dailyId) {
        return enshrineMapper.selectForHave(userId,dailyId);
    }

    public List<Daily> selectMy(Long userId) {
        List<Enshrine> enshrines = enshrineMapper.selectMy(userId);
        List<Daily> dailies = new ArrayList<>();
        for (int i = 0; i < enshrines.size(); i++) {
            Enshrine enshrine = enshrines.get(i);
            dailies.add(dailyMapper.selectByPrimaryKey(enshrine.getD_id()));
        }
        return dailies;
    }
}
